package com.justreading.bio;

import java.io.IOException;
import java.io.OutputStream;
import java.net.*;

/**
 * @author LYJ
 * @Description
 * @date 2021 年 09 月 28 日 下午8:05
 */
public class BIOClient {
    public static void main(String[] args) throws UnknownHostException {
        for (int i = 0; i < 10; i++) {
            new Thread(BIOClient::toConnection, "线程" + i).start();
        }
    }

    private static void toConnection() {
        Socket socket = null;
        OutputStream os = null;
        try {
            socket = new Socket(InetAddress.getLocalHost(), 6666);
            os = socket.getOutputStream();
            os.write("我是客户端1".getBytes());
            os.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (socket != null) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
